package com.library.bookmanagement.controller;

import com.library.bookmanagement.service.UserService;
import com.library.bookmanagement.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：ZXM
 * @date ：Created in 2020/5/11 15:36
 * @description：
 */
@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@ResponseBody
@RequestMapping("/user")
@Api(value = "用户Controller",tags = {"用户接口"})
public class UserController {
    @Autowired
    private UserService userService;


    /**
    * @Description: 借阅图书
    * @Param: [userId, bookId]
    * @return: com.library.bookmanagement.util.ResultUtil
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation(value = "借阅图书")
    @GetMapping("/borrow/book")
    public ResultUtil borrowBook(
            @ApiParam(value = "用户Id",name = "userId")
            @RequestParam(name = "userId") Integer userId,
            @ApiParam(value = "书籍Id",name = "bookId")
            @RequestParam(name = "bookId") Integer bookId
    ){
        return userService.borrowBookByReadKey(userId,bookId);
    }

    /**
    * @Description: 归还图书
    * @Param: [userId, bookId]
    * @return: com.library.bookmanagement.util.ResultUtil
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation(value = "归还图书")
    @GetMapping("/borrow/back")
    public ResultUtil backBook(
      @ApiParam(value = "用户Id",name = "userId")
      @RequestParam(name = "userId") Integer userId,
      @ApiParam(value = "书籍Id",name = "bookId")
      @RequestParam(name = "bookId") Integer bookId
    ){
        return userService.backBookByReadKey(userId,bookId);
    }

    /**
    * @Description: 预定图书
    * @Param: [userId, bookId]
    * @return: com.library.bookmanagement.util.ResultUtil
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation(value = "预定图书")
    @GetMapping("/reserve/book")
    public ResultUtil reserveBook(
            @ApiParam(value = "用户Id",name = "userId")
            @RequestParam(name = "userId") Integer userId,
            @ApiParam(value = "书籍Id",name = "bookId")
            @RequestParam(name = "bookId") Integer bookId
    ){
        return userService.reserveBookByReserveKey(userId,bookId);
    }

    /**
    * @Description: 取消预定
    * @Param: [userId, bookId]
    * @return: com.library.bookmanagement.util.ResultUtil
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation(value = "取消预定")
    @GetMapping("/reserve/cancel")
    public ResultUtil cancelReserve(
            @ApiParam(value = "用户Id",name = "userId")
            @RequestParam(name = "userId") Integer userId,
            @ApiParam(value = "书籍Id",name = "bookId")
            @RequestParam(name = "bookId") Integer bookId
    ){
        return userService.cancelReserveByKey(userId,bookId);
    }

}
